Skip to content

Refactor Node.js server from CommonJS to ESM#400

Merged
electerious merged 6 commits intodevelopfrom
copilot/refactor-nodejs-server-to-esm
Feb 21, 2026
Merged

Refactor Node.js server from CommonJS to ESM#400
electerious merged 6 commits intodevelopfrom
copilot/refactor-nodejs-server-to-esm

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 20, 2026

Converts the entire server-side codebase from CommonJS (require/module.exports) to ES Modules (import/export), following ESM best practices throughout.

Core changes

  • package.json: Added "type": "module"
  • Removed all 'use strict' directives (implicit in ESM)
  • All relative imports include explicit .js extensions (required by Node.js ESM resolver)

Export strategy

Files previously forced to bundle multiple exports into a single object now use proper named exports:

// Before
module.exports = { VIEWS_TYPE_UNIQUE, VIEWS_TYPE_TOTAL }

// After
export const VIEWS_TYPE_UNIQUE = 'UNIQUE'
export const VIEWS_TYPE_TOTAL = 'TOTAL'
  • Named exports: constants, multi-function database modules (CRUD), utils with multiple related values
  • Default exports: single-purpose files — aggregations, stages, models, single-function utils

Notable conversions

  • __dirnamefileURLToPath(import.meta.url) + dirname()
  • require('dotenv').config()import 'dotenv/config'
  • Lazy require() inside functions (src/ui/index.js) → dynamic import()
  • require.resolve()createRequire(import.meta.url).resolve()
  • exports.handler = ... (functions/api.js) → export { handler } from '...'

CJS interop fixes

Some dependencies don't expose named ESM exports and needed workarounds:

  • signale: default import + destructure for Signale
  • date-fns-tz: import { utcToZonedTime } from 'date-fns-tz/esm' (uses the package's ESM entry point)
  • micro / microrouter: default import + destructure for send, createError, router, del, etc.

UI scripts

src/ui/scripts/utils/rangeLabel.js was using a default import from constants/ranges which became named exports — updated to destructured named imports.

All test files converted to ESM accordingly.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fastdl.mongodb.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./postinstall.js (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node node_modules/.bin/ava (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node node_modules/.bin/ava rgo/bin/git bash --no�� --noprofile (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ackee Ready Ready Preview, Comment Feb 21, 2026 10:52am

Co-authored-by: electerious <499088+electerious@users.noreply.github.com>
…Label.js

Co-authored-by: electerious <499088+electerious@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Node.js server from CommonJS to ESM Refactor Node.js server from CommonJS to ESM Feb 20, 2026
Copilot AI requested a review from electerious February 20, 2026 16:36
…ilt-in fetch does not support modifying the Host header
@electerious electerious marked this pull request as ready for review February 21, 2026 10:53
@electerious electerious merged commit 186d700 into develop Feb 21, 2026
14 checks passed
@electerious electerious deleted the copilot/refactor-nodejs-server-to-esm branch February 21, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants